import React, {Component} from 'react';

class App extends Component {
    /********方法一********/
    //定义状态
   /* a = 100
    state = {
        text1: '收藏',
        show:true,
    }*/
    /****************/

    /********方法二********/

    constructor() {
        super();
        this.state={
            text1: '收藏',
            show:true,
        }
    }

    /****************/

    render() {
        var text = '收藏'
        return (
            <div>
                <h1>1111</h1>

                <button onClick={() => {
                    this.setState(
                        {
                            text1: '取消收藏',
                            show:!this.state.show
                        }//间接修改状态
                    )

                    if(this.state.show){
                        console.log(111)
                    }
                }}>
                    <div>{this.state.show?'收藏':'取消收藏'}</div>
                    <br/>
                    <div>{this.state.text1}</div>

                </button>
            </div>
        );
    }
}

export default App;